package com.yixun.qfbao.common.model;

import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

public class PageDTO {
    public static final Integer DEFAULT_PAGENUM = 1;
    public static final Integer DEFAULT_PAGESIZE = 20;
    public static final Integer MAX_PAGESIZE = 10000;
    public static final String DESC = "desc";
    public static final String ASC = "asc";
    @ApiModelProperty("每页大小,默认值为20")
    @NotNull
    @Min(0L)
    private Integer pageSize;
    @ApiModelProperty("当前页，默认值为1")
    @NotNull
    @Min(0L)
    private Integer pageNum;
    @ApiModelProperty("排序字段")
    private String sortBy;
    @ApiModelProperty("排序方式,升序asc,降序desc")
    private String desc;
    private Integer offset;

    public PageDTO() {
        this.pageSize = DEFAULT_PAGESIZE;
        this.pageNum = DEFAULT_PAGENUM;
    }

    public PageDTO(Integer pageNum, Integer pageSize) {
        this.pageSize = DEFAULT_PAGESIZE;
        this.pageNum = DEFAULT_PAGENUM;
        this.pageSize = pageSize;
        this.pageNum = pageNum;
    }

    public PageDTO(Integer pageNum, Integer pageSize, String sortBy, String desc) {
        this.pageSize = DEFAULT_PAGESIZE;
        this.pageNum = DEFAULT_PAGENUM;
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.sortBy = sortBy;
        this.desc = desc;
    }

    public Integer getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNum() {
        return this.pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public String getSortBy() {
        return this.sortBy;
    }

    public void setSortBy(String sortBy) {
        this.sortBy = sortBy;
    }

    public String getDesc() {
        return this.desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Integer getOffset() {
        return (this.getPageNum() - 1) * this.getPageSize();
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }
}
